package JavaCore;

public class ArrayObject7 {
	
	public ArrayObject7(){
		Data7[] d = new Data7[4];
		
		d[0] = new Data7("Kim",90,80,90,80);
		d[1] = new Data7("Lee",80,80,70,60);
		d[2] = new Data7("Park",70,80,90,60);
		d[3] = new Data7("Choi",80,90,90,100);
		
		prn(d);
		System.out.println();
		sort(d);
		prn(d);
	}
	
	public void sort(Data7[] a){
		Data7 temp=null;		
		
		for(int i=0;i<a.length-1;i++){
			for (int j=i+1;j<a.length;j++){
				if(a[i].avg<a[j].avg){
					temp=a[i];
					a[i]=a[j];
					a[j]=temp;					
				}
			}
		}
		
	}
	
	public void prn(Data7[] a){
		System.out.printf("%-5s%-4s%-4s%-4s%-5s%-4s%-4s\n","Name","Kor","Mat","Eng","Comp","Tot","Avg");
		for(int i=0;i<a.length;i++){
			System.out.printf("%-5s%-4s%-4s%-4s%-5s%-4s%-4s\n",a[i].name,a[i].kor,a[i].mat,a[i].eng,a[i].comp,a[i].tot,a[i].avg);
		}
	}

	
	public static void main(String[] args) {
		new ArrayObject7();
	}

}
